package com.yf.tz.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import java.util.Map;
import com.yf.consts.DaoConst;
import com.yf.tz.entity.MallSkuEntity;
import com.yf.tz.service.MallSkuService;
import com.yf.response.R;


/**
 * 产品规格Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Wed Jul 01 16:32:18 CST 2020
 */
@RestController
@RequestMapping("/mall/sku")
public class MallSkuController {
    @Autowired
    private MallSkuService mallSkuService;

    /**
     * 列表产品规格
     */
    @SysLog("查看产品规格")
    @RequestMapping("/list")
    @RequiresPermissions("mall:sku:list")
    public R list(@RequestParam Map<String,Object> params) {
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<MallSkuEntity> mallSkuList = mallSkuService.queryList(params);
        return R.ok(new PageInfo(mallSkuList));
    }

    /**
     * 查看产品规格
     */
    @SysLog("查看产品规格")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("mall:sku:info")
    public R info(@PathVariable("id") Long id) {
        MallSkuEntity mallSku = mallSkuService.get(id);

        return R.ok(mallSku);
    }

    /**
     * 保存产品规格
     */
    @SysLog("保存产品规格")
    @RequestMapping("/save")
    @RequiresPermissions("mall:sku:save")
    public R save(MallSkuEntity mallSku) {
        mallSkuService.save(mallSku);

        return R.ok(mallSku);
    }

    /**
     * 修改产品规格
     */
    @SysLog("修改产品规格")
    @RequestMapping("/update")
    @RequiresPermissions("mall:sku:update")
    public R update(MallSkuEntity mallSku) {
        mallSkuService.update(mallSku);

        return R.ok(mallSku);
    }

    /**
     * 删除产品规格
     */
    @SysLog("删除产品规格")
    @RequestMapping("/delete")
    @RequiresPermissions("mall:sku:delete")
    public R delete(Long[]ids) {
        mallSkuService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有产品规格
     */
    @SysLog("所有产品规格")
    @RequestMapping("/all")
    public R queryAll (@RequestParam Map<String,Object> params) {

        List<MallSkuEntity> mallSkuList = mallSkuService.queryList(params);

        return R.ok(mallSkuList);
    }

    /***********自定义开始***********/
}
